package i_sort;

import java.util.Arrays;

//冒泡排序
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {8,2,3,7,1};

        for (int i = 0; i < arr.length - 1; i++) { // 0 ~ 4
            for (int j = 0; j + 1 < arr.length - i; j++) {
                //数据交换 每次冒泡从下标0开始进行
                if (arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }

            }
        }
        System.out.println(Arrays.toString(arr));

    }
}
